package com.devenv.dto;

import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Map;

/**
 * 用户数据传输对象
 * <p>
 * 用于在控制器层和服务层之间传输用户数据，不包含敏感信息如密码
 * </p>
 * 
 * @author DevEnv OpenSource Team
 * @version 1.0.0
 * @since 1.0.0
 */
@Data
public class UserDTO {
    private Long id;
    private String username;
    private String email;
    private String nickname;
    private String avatarUrl;
    private String phone;
    private String bio;
    private String loginType;
    private Integer status;
    private String role;
    private Long loginCount;
    private Integer scriptGenerationCount;
    private Integer templateCreationCount;
    private LocalDateTime lastLoginTime;
    private LocalDateTime lastActiveTime;
    private BigDecimal profileCompletion;
    private Map<String, Object> preferences;
    private Boolean emailVerified;
    private Boolean phoneVerified;
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;

    /**
     * 获取状态描述
     */
    public String getStatusDescription() {
        if (status == null) return "未知";
        return status == 1 ? "正常" : "禁用";
    }

    /**
     * 获取登录类型描述
     */
    public String getLoginTypeDescription() {
        if (loginType == null) return "未知";
        switch (loginType.toLowerCase()) {
            case "normal": return "普通登录";
            case "oauth": return "第三方登录";
            default: return loginType;
        }
    }

    /**
     * 检查用户是否为管理员
     */
    public boolean isAdmin() {
        return "ADMIN".equals(role) || "SUPER_ADMIN".equals(role);
    }

    /**
     * 检查账户是否活跃
     */
    public boolean isActive() {
        return status != null && status == 1;
    }

    /**
     * 获取资料完整度百分比
     */
    public int getProfileCompletionPercentage() {
        if (profileCompletion == null) return 0;
        return profileCompletion.multiply(BigDecimal.valueOf(100)).intValue();
    }
}
